package com.example.qxfw.dzzh.service.impl;

import com.example.qxfw.common.entity.xt.DzjcTmset;
import com.example.qxfw.dzzh.mapper.DzjcTmsetMapper;
import com.example.qxfw.dzzh.service.DzjcTmsetService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class DzjcTmsetServiceImpl implements DzjcTmsetService {

    @Autowired
    private DzjcTmsetMapper dzjcTmsetMapper;

    @Override
    public List<DzjcTmset> list() {
        List<DzjcTmset> dzjcTmsets = dzjcTmsetMapper.selectList(null);
        //过滤颜色为16进制
        return dzjcTmsets.stream().map(
                i->{
                    DzjcTmset bo = new DzjcTmset();
                    BeanUtils.copyProperties(i,bo);
                    //过滤空白字符
                    bo.setType(bo.getType().trim());
                    bo.setColors(bo.getColors().trim());
                    bo.setColors("#"+Integer.toHexString(Integer.parseInt(bo.getColors())));
                    return bo;
                }
        ).collect(Collectors.toList());
    }

    @Override
    public DzjcTmset save(DzjcTmset dzjcTmset) {
        int rows = dzjcTmsetMapper.insert(dzjcTmset);
        return rows==0?null:dzjcTmset;
    }

    @Override
    public DzjcTmset update(DzjcTmset dzjcTmset) {
        int rows = dzjcTmsetMapper.updateById(dzjcTmset);
        return rows==0?null:dzjcTmset;
    }

    @Override
    public Integer deleteById(Integer id) {
        int rows = dzjcTmsetMapper.deleteById(id);
        return rows>0?id:-1;
    }


}
